package com.yunquan.ohana.ui.calendar.adapter

import androidx.core.graphics.toColorInt
import androidx.databinding.ViewDataBinding
import com.yunquan.ohana.databinding.ItemScheduleBinding
import com.yunquan.ohana.ui.calendar.CalendarMenuViewModel
import com.yunquan.ohana.ui.calendar.EventItemViewModel
import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter

class EventAdapter : BindingRecyclerViewAdapter<EventItemViewModel<CalendarMenuViewModel>>() {
    override fun onBindBinding(
        binding: ViewDataBinding,
        variableId: Int,
        layoutRes: Int,
        position: Int,
        item: EventItemViewModel<CalendarMenuViewModel>?,
    ) {
        super.onBindBinding(binding, variableId, layoutRes, position, item)
        if (binding is ItemScheduleBinding) {
            val firstColorData = item?.data?.scheduleToRoleVos?.firstOrNull()?.getColorData()
            val outColor = firstColorData?.inner?.toColorInt() ?: 0
            val innerColor = firstColorData?.outer?.toColorInt() ?: 0
            binding.vOut.helper.backgroundColorNormal = outColor
            binding.clInner.helper.backgroundColorNormal = innerColor
            binding.tvRoleName.helper.backgroundColorNormal = outColor
        }
    }
}